<?php

namespace app\service\tag;

use app\models\tableModel\NewsCategoryModel;
use app\models\tableModel\PositionDataModel;
use yii\base\Model;

/**
 * 推荐位 模板标签
 * Class NewsCategoryList
 * @package app\models
 */
class Position extends Model
{

    /**
     * 最终数据
     * @var
     */
    public $data;

    /**
     * 推荐位编号
     * @var
     */
    public $posId;

    /**
     * 展示规定字段
     * @var array
     */
    public $fields = [
        'id',
        'from_type',
        'from_id',
        'data'
    ];

    /**
     * @throws \yii\console\Exception
     */
    public function init()
    {
        parent::init();
        $this->run();
    }

    public function beforeRun()
    {

    }

    public function afterRun()
    {

    }

    /**
     * 运行总方法
     * @return array
     * @throws \yii\console\Exception
     */
    public function run()
    {

        // 父级别[model]
        $model = PositionDataModel::loadModel();

        // 数据列表
        $this->data = $model->loadWhere([
            'pos_id' => $this->posId
        ])->getPaginate(1, 999999, $this->fields);

        return array_column($this->data->getList(), 'data');
    }
}
